package com.chtw.service;

import java.util.List;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import com.chtw.dao.TeacherDAO;
import com.chtw.dao.TeacherInfoMapper;
import com.chtw.entity.TeacherInfo;
import com.chtw.entity.TeacherInfoExample;
import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;

@Service
public class TeacherService {

	@Autowired
	private TeacherDAO teacherDAO;
	
	@Autowired
	private TeacherInfoMapper infoMapper;
	
	public List<TeacherInfo> getAll(){
		return infoMapper.selectByExample(null);
	}

	/**
	 * 获取辅导员列表
	 * @return
	 */
	public List<TeacherInfo> getListBytno() {
		return infoMapper.selectByExample(null);
	}

	
	/**
	 * 含有条件的分页查询
	 * @param parseInt
	 * @param teacherInfo
	 * @return
	 */
	public PageInfo<TeacherInfo> page(int nowpage, TeacherInfo teacherInfo) {
		System.out.println(teacherInfo.getEntryData()+"--"+teacherInfo.getTeachId());
		PageHelper.startPage(nowpage, 10);
		TeacherInfoExample example = new TeacherInfoExample();
		TeacherInfoExample.Criteria cre = example.createCriteria();
		if(teacherInfo.getTeachId()==null) {
			if(!teacherInfo.getEntryData().equals("0")) {
				cre.andEntryDataEqualTo(teacherInfo.getEntryData());
			}
		}else if(teacherInfo.getTeachId()!=null) {
			cre.andTeachIdEqualTo(teacherInfo.getTeachId());
		}
		List<TeacherInfo> lists = infoMapper.selectByExample(example);
		PageInfo<TeacherInfo> info = new PageInfo<TeacherInfo>(lists);
		return info;
	}

	/**
	 * 入职时间
	 * @return
	 */
	public List<TeacherInfo> getListByTime() {
		List<TeacherInfo> tiList = infoMapper.getListByTime();
		return tiList;
	}

	/**
	 * 无查询条件的分页
	 * @param i
	 * @return
	 */
	public PageInfo<TeacherInfo> page(int i) {
		PageHelper.startPage(i, 10);
		List<TeacherInfo> lists = infoMapper.selectByExample(new TeacherInfoExample());
		PageInfo<TeacherInfo> info = new PageInfo<TeacherInfo>(lists);
		return info;
	}

	/**
	 * 删除
	 * @param parseInt
	 * @return
	 */
	public int delete(int teachId) {
		int i = infoMapper.deleteByPrimaryKey(teachId);
		return i;
	}

	/**
	 * 按照主键查询
	 * @param parseInt
	 * @return
	 */
	public TeacherInfo getinfo(int teachId) {
		TeacherInfo teach = infoMapper.selectByPrimaryKey(teachId);
		return teach;
	}

	/**
	 * 修改数据
	 * @param teach
	 * @return
	 */
	public int updateteach(TeacherInfo teach) {
		TeacherInfoExample example = new TeacherInfoExample();
		TeacherInfoExample.Criteria cre = example.createCriteria();
		cre.andTeachIdEqualTo(teach.getTeachId());
		int i = infoMapper.updateByExampleSelective(teach,example);
		return i;
	}

	/**
	 * 添加
	 * @param teach
	 * @return
	 */
	public int addteach(TeacherInfo teach) {
		int i = infoMapper.insertSelective(teach);
		return i;
	}

	/**
	 * 导出
	 * @param teach
	 * @return
	 */
	public List<TeacherInfo> search(TeacherInfo teach) {
		TeacherInfoExample example = new TeacherInfoExample();
		TeacherInfoExample.Criteria cre = example.createCriteria();
		if(teach.getTeachId()==null) {
			if(!teach.getEntryData().equals("0")) {
				cre.andEntryDataEqualTo(teach.getEntryData());
			}
		}else if(teach.getTeachId()!=null) {
			cre.andTeachIdEqualTo(teach.getTeachId());
		}
		List<TeacherInfo> lists = infoMapper.selectByExample(example);
		return lists;
	}

	
}
